package com.culturalCenter.dataCenter.mapper.site;

import com.culturalCenter.dataCenter.customEntity.site.CustomSiteAlerts;
import com.culturalCenter.dataCenter.entity.site.SiteAlertsMonth;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface SiteAlertsMonthMapper extends BaseMapper<SiteAlertsMonth> {

    /**
     * 月警报数统计
     *
     * @param type
     * @param startDate
     * @param endDate
     * @param date
     * @param siteId
     *
     * @return
     */
    @Select("SELECT COUNT(*) FROM cdc_site_alerts " +
            "WHERE infoType = #{type} AND DATE_FORMAT(alertsTime, '%d') >= #{startDate} " +
            "AND DATE_FORMAT( alertsTime, '%d' ) <= #{endDate} AND DATE_FORMAT(alertsTime, '%Y-%m')=DATE_FORMAT(#{date}, '%Y-%m') AND siteId=#{siteId}")
    Integer getCountByDate(@Param("type") int type, @Param("startDate") int startDate, @Param("endDate") int endDate, @Param("date") Date date, @Param("siteId") String siteId);

    /**
     * 月警报类型占比统计
     *
     * @param type
     * @param siteId
     *
     * @return
     */
//    @Select("SELECT alertsInfo, COUNT(*) num FROM cdc_site_alerts " +
//            "WHERE infoType = #{type} AND DATE_FORMAT(alertsTime, '%Y-%m')=DATE_FORMAT(#{date}, '%Y-%m') AND siteId=#{siteId} GROUP BY alertsInfo")
    List<CustomSiteAlerts> getTypeCount(@Param("type") int type, @Param("siteId") String siteId);

    /**
     * 清空表
     */
    @Delete("TRUNCATE cdc_site_alerts_month")
    void deleteAll();

    /**
     * 批量插入
     *
     * @param siteAlertsMonthList
     */
    void insertBatch(List<SiteAlertsMonth> siteAlertsMonthList);

    Integer getAlertCountByDate(@Param("type") int type,
                                @Param("startDate")int startDate,
                                @Param("endDate")int endDate,
                                @Param("siteId")String siteId);
}
